package controller

import (
	"fx_swift_boss/api"
	"fx_swift_boss/internal/service"
	"fx_swift_boss/pkg/code"
	"fx_swift_boss/pkg/internalerrors"
	"github.com/gin-gonic/gin"
	"net/http"
)

// If项目boss端首页交易数据
func IfCollectTrends(c *gin.Context) {
	currency := c.Query("currency")
	year := c.Query("year")
	result, err := service.NewIndexSrv().IfCollectTrends(c, &api.CollectTrendsReq{Currency: currency, Year: year})
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, result)
	}
}

// If项目boss端首页交易数据
func IfPayerTrends(c *gin.Context) {
	currency := c.Query("currency")
	year := c.Query("year")
	result, err := service.NewIndexSrv().IfPayerTrends(c, &api.IfPayerTrendsReq{Currency: currency, Year: year})
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, result)
	}
}

// If项目boss端分润总金额
func IfTotalCommission(c *gin.Context) {
	result, err := service.NewIndexSrv().IfTotalCommission(c)
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, result)
	}
}

// If项目boss端代理商分润总金额
func IfAgentTotalCommission(c *gin.Context) {
	result, err := service.NewIndexSrv().IfAgentTotalCommission(c)
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, result)
	}
}

// If项目企业账户总金额
func IfCompanyAccount(c *gin.Context) {
	result, err := service.NewIndexSrv().IfCompanyAccount(c)
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, result)
	}
}

// If项目收款总金额
func IfCollectionTotalAmount(c *gin.Context) {
	result, err := service.NewIndexSrv().IfCollectionTotalAmount(c)
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, result)
	}
}

// If项目付款总金额
func IfPayTotalAmount(c *gin.Context) {
	result, err := service.NewIndexSrv().IfPayTotalAmount(c)
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, result)
	}
}
